define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'order/index/user_id/'+userId,
        index2_url: 'order/index2',
        add_url: 'order/add',
        edit_url: 'order/edit',
        delete_url: 'order/delete',
        export_url: 'order/export',
        modify_url: 'order/modify',
        send_url: 'order/send',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'/*, 'add'*/, 'delete'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id',fieldAlias: 'o.id'},
                    {field: 'order_no', title: '订单号', width: 200,fieldAlias: 'o.order_no'},
                    {field: 'user_id', title: '用户ID', hide: true, searchOp: '=',fieldAlias: 'o.user_id'},
                    {field: 'nickname', title: '用户昵称', search: false, width: 150,fieldAlias: 'u.nickname'},
                    {field: 'shop_id', title: '店铺ID', hide: true, searchOp: '=',fieldAlias: 'o.shop_id'},
                    {field: 'shop_name', title: '店铺名', width: 200},
                    {width: 80, field: 'goods_id', title: '商品ID',fieldAlias: 'o.goods_id'},
                    {width: 120, field: 'goods_name', title: '商品名称',search:false},
                    // {field: 'sku_id', title: '规格ID',search:false},
                    {field: 'price', title: '订单价格', width: 100, search: false,fieldAlias: 'o.price'},
                    {field: 'pay_status', title: '支付状态', selectList: {0: '待支付', 1: '已支付'}, width: 100},
                    {
                        field: 'status',
                        title: '订单状态',
                        selectList: {0: '进行中', 1: '已完成', 2: '已取消', 3: '已退款完成'},
                        width: 100,
                        fieldAlias: 'o.status'
                    },
                    {
                        field: 'refund_status',
                        title: '退款状态',
                        selectList: {0: '未申请', 1: '申请退款', 2: '退款成功', 3: '退款取消'},
                        width: 100,
                        fieldAlias: 'o.refund_status'
                    },
                    /*{field: 'name', title: '收货人'},
                    {field: 'phone', title: '收货电话'},,
                    {field: 'receive_time', title: '收货时间'},*/
                    {field: 'express_time', title: '发货时间', width: 200, search: 'range',fieldAlias:'o.express_time'},
                    {field: 'create_time', title: '创建时间', width: 200, search: 'range',fieldAlias:'o.create_time'},
                    {
                        width: 200, title: '操作', fixed: 'right', templet: function (k, v) {
                            if (k.express_time != '-') {
                                v.operat.splice(0,1);
                            }
                            //console.log(k, v);
                            return ea.table.tool(k, v);
                        },
                        operat: [
                            //'edit',
                            [{
                                text: '发货',
                                url: init.send_url,
                                method: 'get',
                                // fieldExtra: {'shop_id': 'id'},
                                auth: 'send',
                                title: '确定发货？',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                            }],
                            'delete']
                    },
                ]],
                done: function () {
                    $(".layui-table-body>table>tbody>tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                    });
                },
            });

            ea.listen();
        },
        index2: function () {
            ea.table.render({
                url: ea.url(init.index2_url),
                init: init,
                toolbar: ['refresh'/*, 'add'*/, 'delete'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id', fieldAlias: 'o.id'},
                    {field: 'order_no', title: '订单号', width: 200, fieldAlias: 'o.order_no'},
                    {field: 'user_id', title: '用户ID', hide: true, searchOp: '=', fieldAlias: 'o.user_id'},
                    {field: 'nickname', title: '用户昵称', search: false, width: 200, fieldAlias: 'u.nickname'},
                    {field: 'shop_id', title: '店铺ID', hide: true, searchOp: '=', fieldAlias: 'o.shop_id'},
                    {field: 'shop_name', title: '店铺名', width: 200},
                    {width: 80, field: 'goods_id', title: '商品ID', fieldAlias: 'o.goods_id'},
                    {width: 250, field: 'goods_name', title: '商品名称', search: false},
                    {width: 120,imageHeight: 80, field: 'goods_img', title: '商品图片',templet: ea.table.image,search: false},
                    {width: 200, field: 'sku_json', title: '规格信息', search: false},
                    {width: 100, field: 'num', title: '订单数量', search: false},
                    {width: 100, field: 'shop_address', title: '收货地址', search: false},
                    // {field: 'sku_id', title: '规格ID',search:false},
                    {field: 'price', title: '订单价格', width: 100, search: false},
                    {
                        field: 'express_status',
                        title: '发货状态',
                        selectList: {1: '已发货', 2: '<div style="color:red">待发货</div>', 3: '无需发货'},
                        width: 100
                    },
                    {field: 'pay_status', title: '支付状态', selectList: {0: '待支付', 1: '已支付'}, width: 100},
                    {
                        field: 'status',
                        title: '订单状态',
                        selectList: {0: '<div style="color:red">进行中</div>', 1: '已完成', 2: '已取消', 3: '已退款完成'},
                        width: 100,
                        fieldAlias: 'o.status'
                    },
                    {
                        field: 'refund_status',
                        title: '退款状态',
                        selectList: {0: '未申请', 1: '申请退款', 2: '退款成功', 3: '退款取消'},
                        width: 100,
                        fieldAlias: 'o.refund_status'
                    },
                    /*{field: 'name', title: '收货人'},
                    {field: 'phone', title: '收货电话'},
                    {field: 'receive_time', title: '收货时间'},*/
                    {field: 'express_time', title: '发货时间', width: 200, search: 'range', fieldAlias: 'o.express_time'},
                    {field: 'create_time', title: '创建时间', width: 200, search: 'range', fieldAlias: 'o.create_time'},
                    {
                        width: 200, title: '操作', fixed: 'right', templet: function (k, v) {
                            if (k.express_time != '-') {
                                v.operat.splice(0,1);
                            }
                            //console.log(k, v);
                            return ea.table.tool(k, v);
                        },
                        operat: [
                            [{
                                text: '发货',
                                url: init.send_url,
                                method: 'get',
                                // fieldExtra: {'shop_id': 'id'},
                                auth: 'send',
                                title: '确定发货？',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                            }],
                            // 'edit',
                            'delete']
                    },
                ]],
                done: function () {
                    $(".layui-table-body>table>tbody>tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                    });
                },
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});